home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / STREAM13.ARJ / CRC16.ASM < prev    next >
Assembly Source File  |  1992-05-12  |  5KB  |  119 lines

  1. IDEAL
  2. ; This CRC-16 routine and tables were converted from C code discovered
  3. ; in rzsz.arc by Chuck Forsberg.  The comments there are:
  4. ;
  5. ; crctab calculated by Mark G. Mendel, Network Systems Corporation
  6. ;
  7. ; updcrc macro derived from article Copyright (C) 1986 Stephen Satchell.
  8. ;  NOTE: First srgument must be in range 0 to 255.
  9. ;        Second argument is referenced twice.
  10. ;
  11. ; Programmers may incorporate any or all code into their programs,
  12. ; giving proper credit within the source. Publication of the
  13. ; source routines is permitted so long as proper credit is given
  14. ; to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
  15. ; Omen Technology.
  16. ;
  17. ; <End of rzsz comments>
  18. ;
  19. ; The C macro is:
  20. ;
  21. ; #define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
  22. ;
  23. ; This routine appears to compute the 16 bit CRC used by XModem and its
  24. ; derivatives.  For transmission, the CRC value should start with 0 and,
  25. ; after the block crc is computed, the value should be updated with two
  26. ; nulls and transmitted high-order byte first.  The computed CRC value
  27. ; on the received block + 2 byte CRC should be zero.
  28. c:\dosauto
  29. ;
  30. ; This TASM conversion done by:
  31. ;
  32. ;   Edwin T. Floyd [76067h747]
  33. ;   #9 Adams Park Ct.
  34. ;   Columbush GA 31909
  35. ;   404-576-3305 (work)
  36. ;   404-322-0076 (home)
  37. ;
  38. ; Borland's Turbo Assembler - TASM is required to assemble this program.
  39. ;
  40. SEGMENT  code BYTE PUBLIC
  41.          ASSUME cs:code
  42. ;            0
  43. crctab   dw     00000h, 01021h, 02042h, 03063h, 04084h, 050a5h, 060c6h, 070e7h
  44.          dw     08108h, 09129h, 0a14ah, 0b16bh, 0c18ch, 0d1adh, 0e1ceh, 0f1efh
  45. ;            1
  46.          dw     01231h, 00210h, 03273h, 02252h, 052b5h, 04294h, 072f7h, 062d6h
  47.          dw     09339h, 08318h, 0b37bh, 0a35ah, 0d3bdh, 0c39ch, 0f3ffh, 0e3deh
  48. ;            2
  49.          dw     02462h, 03443h, 00420h, 01401h, 064e6h, 074c7h, 044a4h, 05485h
  50.          dw     0a56ah, 0b54bh, 08528h, 09509h, 0e5eeh, 0f5cfh, 0c5ach, 0d58dh
  51. ;            3
  52.          dw     03653h, 02672h, 01611h, 00630h, 076d7h, 066f6h, 05695h, 046b4h
  53.          dw     0b75bh, 0a77ah, 09719h, 08738h, 0f7dfh, 0e7feh, 0d79dh, 0c7bch
  54. ;            4
  55.          dw     048c4h, 058e5h, 06886h, 078a7h, 00840h, 01861h, 02802h, 03823h
  56.          dw     0c9cch, 0d9edh, 0e98eh, 0f9afh, 08948h, 09969h, 0a90ah, 0b92bh
  57. ;            5
  58.          dw     05af5h, 04ad4h, 07ab7h, 06a96h, 01a71h, 00a50h, 03a33h, 02a12h
  59.          dw     0dbfdh, 0cbdch, 0fbbfh, 0eb9eh, 09b79h, 08b58h, 0bb3bh, 0ab1ah
  60. ;            6
  61.          dw     06ca6h, 07c87h, 04ce4h, 05cc5h, 02c22h, 03c03h, 00c60h, 01c41h
  62.          dw     0edaeh, 0fd8fh, 0cdech, 0ddcdh, 0ad2ah, 0bd0bh, 08d68h, 09d49h
  63. ;            7
  64.          dw     07e97h, 06eb6h, 05ed5h, 04ef4h, 03e13h, 02e32h, 01e51h, 00e70h
  65.          dw     0ff9fh, 0efbeh, 0dfddh, 0cffch, 0bf1bh, 0af3ah, 09f59h, 08f78h
  66. ;            8
  67.          dw     09188h, 081a9h, 0b1cah, 0a1ebh, 0d10ch, 0c12dh, 0f14eh, 0e16fh
  68.          dw     01080h, 000a1h, 030c2h, 020e3h, 05004h, 04025h, 07046h, 06067h
  69. ;            9
  70.          dw     083b9h, 09398h, 0a3fbh, 0b3dah, 0c33dh, 0d31ch, 0e37fh, 0f35eh
  71.          dw     002b1h, 01290h, 022f3h, 032d2h, 04235h, 05214h, 06277h, 07256h
  72. ;            A
  73.          dw     0b5eah, 0a5cbh, 095a8h, 08589h, 0f56eh, 0e54fh, 0d52ch, 0c50dh
  74.          dw     034e2h, 024c3h, 014a0h, 00481h, 07466h, 06447h, 05424h, 04405h
  75. ;            B
  76.          dw     0a7dbh, 0b7fah, 08799h, 097b8h, 0e75fh, 0f77eh, 0c71dh, 0d73ch
  77.          dw     026d3h, 036f2h, 00691h, 016b0h, 06657h, 07676h, 04615h, 05634h
  78. ;            C
  79.          dw     0d94ch, 0c96dh, 0f90eh, 0e92fh, 099c8h, 089e9h, 0b98ah, 0a9abh
  80.          dw     05844h, 04865h, 07806h, 06827h, 018c0h, 008e1h, 03882h, 028a3h
  81. ;            D
  82.          dw     0cb7dh, 0db5ch, 0eb3fh, 0fb1eh, 08bf9h, 09bd8h, 0abbbh, 0bb9ah
  83.          dw     04a75h, 05a54h, 06a37h, 07a16h, 00af1h, 01ad0h, 02ab3h, 03a92h
  84. ;            E
  85.          dw     0fd2eh, 0ed0fh, 0dd6ch, 0cd4dh, 0bdaah, 0ad8bh, 09de8h, 08dc9h
  86.          dw     07c26h, 06c07h, 05c64h, 04c45h, 03ca2h, 02c83h, 01ce0h, 00cc1h
  87. ;            F
  88.          dw     0ef1fh, 0ff3eh, 0cf5dh, 0df7ch, 0af9bh, 0bfbah, 08fd9h, 09ff8h
  89.          dw     06e17h, 07e36h, 04e55h, 05e74h, 02e93h, 03eb2h, 00ed1h, 01ef0h
  90.  
  91.          MODEL TPASCAL
  92.  
  93. PUBLIC   UpdateCRC16
  94. PROC     UpdateCRC16 FAR initcrc:WORD,inbuf:DWORD,inlen:WORD
  95. ; UpdateCRC16 takes an initial CRC value and updates it with inlen bytes from
  96. ; inbuf. The updated CRC is returned in AX.  The Pascal declaration is:
  97. ; Function UpdateCRC16(InitCRC : Word; Var InBuf; InLen : Word) : Word;
  98. ; Stomps registers: AX,BX,CX,SI
  99.          push   ds
  100.          lds    si,[inbuf]    ; ds:si := ^inbuf
  101.          mov    ax,[initcrc]  ; ax := initcrc
  102.          mov    cx,[inlen]    ; cx := inlen
  103.          or     cx,cx
  104.          jz     @@done
  105. @@loop:
  106.          xor    bh,bh
  107.          mov    bl,ah
  108.          mov    ah,al
  109.          lodsb
  110.          shl    bx,1
  111.          xor    ax,[crctab+bx]
  112.          loop   @@loop
  113. @@done:
  114.          pop    ds
  115.          ret
  116. ENDP
  117.  
  118. ENDS
  119. END